/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#include "MockMessage.h"

#include <assert.h>

const char* MockMessage::hit_none = "Nothing Hit";
const char* MockMessage::hit_execute = "Executed";
const char* MockMessage::hit_execute_HasTest = "Executed but had a test subscriber";
const char* MockMessage::hit_dispatch_ToNULL = "Dispatched to a NULL subscriber";
const char* MockMessage::hit_dispatch_ToTest = "Dispatched to a test subscriber";
const char* MockMessage::hit_dispatch_ToUnknown = "Dispatched to an unknown subscriber";

MockSubscriber::MockSubscriber( void )
{
}

MockSubscriber::~MockSubscriber( void )
{
}

MockMessage::MockMessage(
    volatile const char*& hit, 
    const Topic& topic,
	Priority priority,
    const Accume& accume )
: SBJ::Arrow::Message( topic, priority )
, m_hit( hit )
, m_test( 0 )
, m_accume( accume )
, m_threadThreshold ( Message::getThreadedThreshold() )
, m_blocks( Message::doesBlockOnDispatch() )
{
  m_hit = hit_none;
}

MockMessage::MockMessage(
    volatile const char*& hit,
    const Topic& topic,
	Priority priority,
    Subscriber* test,
    const Accume& accume )
: SBJ::Arrow::Message( topic, priority )
, m_hit( hit )
, m_test( test )
, m_accume( accume )
, m_threadThreshold ( Message::getThreadedThreshold() )
, m_blocks( Message::doesBlockOnDispatch() )
{
  m_hit = hit_none;
}

MockMessage::MockMessage( MockMessage& rhs )
: SBJ::Arrow::Message( rhs )
, m_hit( rhs.m_hit )
, m_test( rhs.m_test )
, m_accume( rhs.m_accume )
, m_threadThreshold ( rhs.m_threadThreshold )
, m_blocks( rhs.m_blocks )
{
}

MockMessage::~MockMessage( void )
{
}

bool
MockMessage::doesConsume( const MockMessage& rhs ) const
{
  return ( m_accume.upper > 0 );
}
	
void
MockMessage::consume( MockMessage& rhs )
{
  ++m_accume.acquired;
}

void
MockMessage::execute( void )
{
  if ( m_test )
    m_hit = hit_execute_HasTest;
  else
    m_hit = hit_execute;
}

bool
MockMessage::beginInvocations( size_t count )
{
	return true;
}

void
MockMessage::invoke( Subscriber* subscriber )
{
  if ( subscriber == 0 )
  {
    m_hit = hit_dispatch_ToNULL;
  }
  else if ( subscriber == m_test )
  {
    m_hit = hit_dispatch_ToTest;
  }
  else
  {
    m_hit = hit_dispatch_ToUnknown;
  }
}

void
MockMessage::endInvocations( void )
{
}

